//
//  BNDOfficeDocListCell.m
//  OfficeDoc
//
//  Created by pie on 2022/4/1.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDOfficeDocListCell.h"
#import "UIImageView+LKWebImage.h"

@interface BNDOfficeDocListCell ()
@property (strong, nonatomic) UILabel *topLabel;
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *subtitleLabel;
@property (strong, nonatomic) UIImageView *iconImageView;
@property (strong, nonatomic) UILabel *timeLabel;
@property (strong, nonatomic) UILabel *dotLabel;

@property (strong, nonatomic) UIView *showView;
@end

@implementation BNDOfficeDocListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.contentView.backgroundColor = UIColorWithHex(0xF6F6F8);
        
        _showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, 130)];
        _showView.backgroundColor = UIColor.whiteColor;
        _showView.layer.cornerRadius = 12;
        [self.contentView addSubview:_showView];
        [_showView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(12, 12, 0, 12));
        }];
        
        _topLabel = [[UILabel alloc] init];
        _topLabel.text = @"置顶";
        _topLabel.font = BNDPFMediumFont(10);
        _topLabel.textAlignment = NSTextAlignmentCenter;
        _topLabel.textColor = UIColorWithHex(0x3770EB);
        _topLabel.layer.cornerRadius = 4;
        _topLabel.layer.masksToBounds = YES;
        _topLabel.layer.borderColor = UIColorWithHex(0x3770EB).CGColor;
        _topLabel.layer.borderWidth = 0.5;
        [self.showView addSubview:_topLabel];
        [_topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(28, 16));
            make.left.mas_equalTo(self.showView.mas_left).offset(16);
            make.top.mas_equalTo(self.showView.mas_top).offset(20);
        }];
        
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"这是公告的标题这个公告有点长标题这个公告有点长";
        _titleLabel.font = BNDPFHeavyFont(16);
        _titleLabel.textColor = UIColorWithHex(0x34363B);
        _titleLabel.numberOfLines = 1;
        [self.showView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.topLabel.mas_right).offset(8);
            make.right.mas_equalTo(self.showView.mas_right).offset(-35);
            make.centerY.mas_equalTo(self.topLabel);
        }];
        
        
        _iconImageView = [[UIImageView alloc] initWithImage:BNDImageNamed(@"bnd_home_tuis_news")];
        [self.showView addSubview:_iconImageView];
        [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(74, 50));
            make.right.mas_equalTo(self.showView.mas_right).offset(-16);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8);
        }];
        
        _subtitleLabel = [[UILabel alloc] init];
        _subtitleLabel.text = @"这是一个公告内容这是一个公告内容这是一个这是一个公告内容这是一个公告内容这是一个";
        _subtitleLabel.font = BNDPFRegularFont(12);
        _subtitleLabel.textColor = UIColorWithHex(0x959BA6);
        _subtitleLabel.numberOfLines = 2;
        [self.showView addSubview:_subtitleLabel];
        [_subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.showView.mas_left).offset(16);
            make.right.mas_equalTo(self.iconImageView.mas_left).offset(-12);
            make.centerY.mas_equalTo(self.iconImageView);
        }];
        
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.text = @"周晓梅   2022-01-14 12:22 ";
        _timeLabel.font = BNDPFRegularFont(12);
        _timeLabel.textColor = UIColorWithHex(0x959BA6);
        _timeLabel.numberOfLines = 1;
        [self.showView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.showView.mas_left).offset(16);
            make.right.mas_equalTo(self.showView.mas_right).offset(-16);
            make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(4);
        }];
        
        _dotLabel = [[UILabel alloc] init];
        _dotLabel.backgroundColor = UIColorWithHex(0xF85757);
        _dotLabel.layer.cornerRadius = 4;
        _dotLabel.layer.masksToBounds = YES;
        _dotLabel.hidden = YES;
        [self.showView addSubview:_dotLabel];
        [_dotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(8, 8));
            make.centerY.mas_equalTo(self.titleLabel);
            make.right.mas_equalTo(self.showView.mas_right).offset(-16);
        }];
        
    }
    
    return self;
}

- (void)setModel:(BNDOfficeDocModel *)model
{
    _model = model;
    
    _titleLabel.attributedText = model.titleAttribute;
    _subtitleLabel.attributedText = model.subtitleAttribute;
    _timeLabel.text = [NSString stringWithFormat:@"%@       %@",model.senderName,model.displayTime];
    [_iconImageView lk_setImageFadeWithURLStr:[[BNDPreference sharedInstance] handleProduceImageUrl:model.coverPic] placeholder:BNDImageNamed(@"bnd_home_tuis_news")];

    
    if(model.isTop){
        [_topLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(28, 16));
        }];
        
        [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.topLabel.mas_right).offset(8);
        
        }];
    }else{
        [_topLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(0, 16));
        }];
        [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.topLabel.mas_right).offset(0);
        }];
    }
    
    if(model.recordId.length ==0){
        self.dotLabel.hidden = YES;
    }else{
        if(model.needSigned == 0){
            if(model.recordType == 0){
                self.dotLabel.hidden = NO;
            }else{
                self.dotLabel.hidden = YES;
            }
        }else{
            if(model.recordType == 1){
                self.dotLabel.hidden = NO;
            }else if(model.recordType == 3){
                self.dotLabel.hidden = YES;
            }
        }
    }

}
@end
